package cn.star.jots.dict.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.dict.pojo.dto.DictQuery;
import cn.star.jots.dict.pojo.dto.DictSaveParam;
import cn.star.jots.dict.pojo.vo.DictVO;
import cn.star.jots.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/v1/dict")
@Api(tags = "字典管理")
@Slf4j
public class DictController {
    @Autowired
    DictService dictService;

    @GetMapping("/select")
    @ApiOperation(value = "查询字典列表")
    public JsonResult select(DictQuery dictQuery){
        log.info("查询字典列表:dictQuery={}",dictQuery);
        List<DictVO> list = dictService.selectAll(dictQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存字典")
    public JsonResult save(DictSaveParam dictSaveParam){
        log.info("保存字典:dict={}",dictSaveParam);
        dictService.save(dictSaveParam);
        return JsonResult.ok();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除字典")
    public JsonResult delete(@PathVariable Long id){
        log.info("删除字典:id={}",id);
        dictService.delete(id);
        return JsonResult.ok();
    }
}
